//
// Created by ruiyan on 2022/1/24.
//

#pragma once


#include<stdio.h>
#include<string.h>
#include<iostream>
#include <thread>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <functional>

typedef std::function<void(char *buf, size_t sz)> Recv_CallBack;


class UdpClient {
public:
    bool Start(const std::string &ip, const int &port, Recv_CallBack callBack);

    bool Stop();

    bool WriteUdp(char *buf, int len);

private:
    int init(const std::string &ip, const int &port);

    static void *start_recvData(void *pArgs);

    void udpRecvproc();

private:
    std::thread *m_recvThread;
    Recv_CallBack m_recvCallBack = nullptr;
    bool m_isStart = false;
    int sock_Client; //�ͻ�������ͨ�ŵ�Socket
    sockaddr_in addr_server;   //�������ĵ�ַ���ݽṹ
};



